package com.init.utils;

import lombok.Data;

@Data
public class Result<T> {
    private final int code;
    private final String message;
    private final T data;

    public Result(int code,String message,T data) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    /**
     * 成功
     * @param data 响应数据
     * @param message 成功信息
     * @param code 状态码
     * @param <T>
     * @return
     */
    public static<T> Result<T> ok(T data,String message,int code) {
        return new Result<T>(200,message,data);
    }

    /**
     * 失败
     * @param message 失败信息
     * @param <T>
     * @return
     */
    public static<T> Result<T> fail(String message) {
        return new Result<T>(500,message,null);
    }
}
